Skip to content

FIX: Index background weights by height level in multi-radar retrievals - #177

Open
Wahaj18 wants to merge 1 commit into
openradar:mainfrom
Wahaj18:fix-142-bg-weights-level
Open

Wahaj18 wants to merge 1 commit into
openradar:mainfrom
Wahaj18:fix-142-bg-weights-level

Conversation

@Wahaj18

@Wahaj18 Wahaj18 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #142

#143 stopped cur_array aliasing the radar weights. The background weights a few lines below still have a problem, which the #143 description already suspected. In both the SciPy and TensorFlow engines, with two or more radars:

  • The mask for level k is read from bg_weights[k] but added to bg_weights[i], where i is the radar index and not a height level. So levels 0 to len(Grids) - 1 collect the background mask of every other level. In the TWP-ICE example, levels 0 and 1 end up with a background weight of 1 everywhere, including the roughly 16% of each level that has dual-Doppler coverage. All other levels are the exact complement of the coverage.
  • When weights_bg is passed in, bg_weights[i] = weights_bg[i] copies only the first len(Grids) levels, and the rest stay 0.

This change adds into bg_weights[k] from a copy, the same way the radar weights now work, and uses weights_bg[k] for each level.

Testing: I added test_twpice_case_bg_weights to test_retrieval.py. It checks that the automatic background weights are the complement of the radar coverage at every level, and that a supplied weights_bg is used unchanged. It fails on main (4663 mismatched points, all in levels 0 and 1) and passes with this change. I ran the same check against the TensorFlow engine, which shows the same mismatch on main and none with the fix. pytest pydda/tests passes, apart from three tests that fail because this machine has no network access to IEM and no cfgrib (HRRR). The TensorFlow tests pass, and pre-commit (black, ruff) is clean.

With two or more radars, the background weight for each pair was taken
from bg_weights[k] (k is the height level) but accumulated into
bg_weights[i] (i is the radar index). Levels 0 to len(Grids) - 1 picked
up the background mask of every other level, so the background
constraint was applied over the whole of the lowest levels, including
points with dual-Doppler coverage. User-supplied weights_bg had the same
problem: only its first len(Grids) levels were used.

Accumulate into bg_weights[k] from a copy, as is already done for the
radar weights, and take weights_bg[k] for each level.

Fixes openradar#142
@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.32%. Comparing base (bbfe417) to head (7e53dca).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pydda/retrieval/wind_retrieve.py 50.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #177      +/-   ##
==========================================
+ Coverage   61.26%   61.32%   +0.06%     
==========================================
  Files          34       34              
  Lines        6012     6020       +8     
==========================================
+ Hits         3683     3692       +9     
+ Misses       2329     2328       -1     
Flag Coverage Δ
unittests 61.32% <78.57%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong calculation in weight if more than 2 radars

1 participant